/*
package com.itheima;

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


@Component
public class OssJavaSdkQuickStart {
    */
/** 生成一个唯一的 Bucket 名称 *//*


    public static void main(String[] args) throws Exception {
        String content="yuanjiun kao";
        String url=upload(content.getBytes(StandardCharsets.UTF_8),"754645.txt");
        System.out.println(url);
    }

    public static String upload(byte[] content ,String fileName) throws Exception{
        // Endpoint以华东1（杭州）为例，填写为https://oss-cn-hangzhou.aliyuncs.com，其它Region请按实际情况填写。oss-cn-shenzhen.aliyuncs.com
        String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";

        String bucketName = "177zhang";
        // 填写Bucket所在地域。以华东1（杭州）为例，Region填写为cn-hangzhou。
        String region = "cn-shenzhen";

        // 从环境变量中获取访问凭证。运行本代码示例之前，请先配置环境变量
        EnvironmentVariableCredentialsProvider credentialsProvider =
                CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();

        // 创建OSSClient实例。
        // 当OSSClient实例不再使用时，调用shutdown方法以释放资源。
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        // 显式声明使用 V4 签名算法
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(credentialsProvider)
                .region(region)
                .build();

        // 2. 上传文件 2025/06/28/123.jpg
       String path= LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
       String objectName=path+"/"+fileName;


        ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(content));
        System.out.println("2. 文件 " + objectName + " 上传成功。");


        //访问文件177zhang.oss-cn-shenzhen.aliyuncs.com/2025/06/28/123.jpg
        String url="https://177zhang.oss-cn-shenzhen.aliyuncs.com/"+objectName;
        return url;
    }
}*/
